home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / viaray.com / VIARAYT1.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-11-09  |  2.7 KB  |  101 lines

  1. program ViArryT1;    {Test ViAray unit      Turbo Pascal 5.5}
  2. {$R-,S-}
  3.  
  4. uses
  5.   Crt,ViAray;
  6.  
  7. type
  8.   ElTyp = record     {data structure of each array element}
  9.             Str : string[50];
  10.             Id  : longint;
  11.           end;
  12. var
  13.   ExitSave : pointer;
  14.   Time : longint absolute $0040:$006C;
  15.   A1 : VirArray;
  16.   ElData : ElTyp;
  17.   ListSize,Elements,BuffSize,BuffSize2,Tick1,I,J : longint;
  18.   ElemSize : word;
  19.  
  20. {$F+} procedure PrgmExit;
  21. begin
  22.   ExitProc := ExitSave;
  23.   if ErrMsg <> '' then Writeln(#13,#10,ErrMsg);
  24. end; {$F-}
  25.  
  26. begin
  27.   ExitSave := ExitProc;
  28.   ExitProc := @PrgmExit;
  29.   Elements := 150;
  30.   ElemSize := SizeOf(ElData);
  31.   BuffSize :=  441;    {RAM buffer is set unrealistically low for demo use}
  32.   BuffSize2 := 1000;
  33.   Writeln(#13,#10,'Initialize array with ',Elements, ' elements and ',BuffSize,
  34.            ' bytes in RAM buffer');
  35.   Init(A1,true,Elements,ElemSize,BuffSize,'VITST.DAT');
  36.   {  Writeln('BSize: ',A1.BSize,'  SSize: ',A1.SSize);  }
  37.   for I := 0 to Elements-1 do
  38.     begin
  39.       ElData.Id := I;
  40.       Accept(A1,ElData,I);
  41.     end;
  42.   if Elements > 20 then ListSize := 20 else ListSize := Elements;
  43.   Writeln('Retrieve from array ',ListSize, ' elements which have a value',
  44.                                                  ' = to the element number:');
  45.   RandSeed := 1;
  46.   for I := 0 to ListSize-1 do
  47.     begin
  48.       J := Random(Elements);
  49.       Write(J:8);
  50.     end;
  51.   Writeln('Actual retrieved values:');
  52.   RandSeed := 1;
  53.   Tick1 := Time;
  54.   for I := 0 to ListSize-1 do
  55.     begin
  56.       J := Random(Elements);
  57.       Retrieve(A1,ElData,J);
  58.       Write(ElData.Id:8);
  59.     end;
  60.   Writeln('Ticks (18.2/sec): ',Time-Tick1);
  61.   Writeln('Resize RAM buffer from ',BuffSize,' to ',BuffSize2,' bytes',
  62.                         ' and retrieve same data:');
  63.   ReSize(A1,Elements,BuffSize2);
  64.   RandSeed := 1;
  65.   Tick1 := Time;
  66.   for I := 0 to ListSize-1 do
  67.     begin
  68.       J := Random(Elements);
  69.       Retrieve(A1,ElData,J);
  70.       Write(ElData.Id:8);
  71.     end;
  72.   Writeln('Ticks (18.2/sec): ',Time-Tick1);
  73.   J := 1;  I := 10;
  74.   Writeln('Swap data between elements ',J,' and ',I,':');
  75.   Write('Before: ');
  76.   Retrieve(A1,ElData,J);
  77.   Write(ElData.Id:8);
  78.   Retrieve(A1,ElData,I);
  79.   Write(ElData.Id:8);
  80.   Swap(A1,J,I);
  81.   Write('      After: ');
  82.   Retrieve(A1,ElData,J);
  83.   Write(ElData.Id:8);
  84.   Retrieve(A1,ElData,I);
  85.   Write(ElData.Id:8);
  86.   Writeln;
  87.   Writeln('Copy data from element ',J,' to ',I,':');
  88.   Write('Before: ');
  89.   Retrieve(A1,ElData,J);
  90.   Write(ElData.Id:8);
  91.   Retrieve(A1,ElData,I);
  92.   Write(ElData.Id:8);
  93.   Copy(A1,A1,J,I);
  94.   Write('      After: ');
  95.   Retrieve(A1,ElData,J);
  96.   Write(ElData.Id:8);
  97.   Retrieve(A1,ElData,I);
  98.   Write(ElData.Id:8);
  99.   Writeln;
  100.   Destroy(A1);
  101. end.